import traceback


class AppError(Exception):
    @staticmethod
    def main():
        try:
            print("Raise an error")
            raise AppError()
        except Exception as e:
            print("Exception? run the except code")
            # 输出异常代码抛出堆栈
            traceback.print_exc()
            print(e)
        else:
            print("No exceptions? run the `else` code.")
        finally:
            print("Always run the finally code")

    def __init__(
        self, message: str = None, error_id: int = None, inner_error: Exception = None
    ) -> None:
        super().__init__()
        self.message = message
        self.error_id = error_id
        self.inner_error = inner_error

    def __str__(self) -> str:
        return f'{"id(" + self.error_id + ")" if self.error_id else ""}'

    def __repr__(self) -> str:
        return f'{"id(" + self.error_id + ")" if self.error_id else ""}'


if __name__ == "__main__":
    AppError.main()
